package app.sb.jly.com.ji_liang_yuan.activitys.commons;

import android.util.Base64;

import java.nio.charset.StandardCharsets;

/**
 * @ProjectName: Ji_liang_yuan2
 * @Package: app.sb.jly.com.ji_liang_yuan.activitys.commons
 * @ClassName: Base64Util
 * @Description: java类作用描述
 * @Author: liuxj
 * @CreateDate: 2023-01-03 16:46
 * @UpdateUser: 更新者
 * @UpdateDate: 2023-01-03 16:46
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class Base64Util {
    public static String strToBase64(String str) {
        byte[] byteStr = str.getBytes(StandardCharsets.UTF_8);
        return Base64.encodeToString(byteStr, Base64.DEFAULT);
    }

    public static String base64ToStr(String str) {
        byte[] byteStr = Base64.decode(str, Base64.DEFAULT);
        return new String(byteStr);
    }

    public static String encode(byte[] key) {
        return Base64.encodeToString(key, Base64.DEFAULT);
    }

    public static byte[] decode(String key) {
        return Base64.decode(key, Base64.DEFAULT);
    }
}
